<template>
  <section id="container">
    <myhead></myhead>
    <mymenu ref="mymenu"></mymenu>
    <section id="main-content">
      <section class="wrapper">
        <div class="row">
          <div class="col-lg-12 main-chart">
            <div class="border-head mm">
              <h3>控制日志</h3>
            </div>
          </div>
        </div>
        <div class="row mb">
          <div class="content-panel mypanel">
            <div class="adv-table">
              <div id="hidden-table-info_wrapper" class="dataTables_wrapper form-inline" role="grid">
                <div class="row-fluid">
                  <div class="col-lg-6 mar">
                    <div class="dataTables_filter" id="hidden-table-info_filter">
                      <label>
                        <select class="form-control" v-model.trim="sendState">
                          <option :value="0" >全部</option>
                          <option :value="1" >成功</option>
                          <option :value="2" >失败</option>
                        </select>
                        <button class="btn btn-success btn-sm" @click="findState">状态查询</button>
                      </label>
                    </div>
                  </div>
                </div>
                <table  class="display table table-bordered dataTable">
                  <thead>
                    <tr role="row">
                      <th class="sorting_asc">学校</th>
                      <th class="sorting">采集器</th>
                      <th class="hidden-phone sorting">盘管</th>
                      <th class="hidden-phone sorting">指令类型</th>
                      <th class="hidden-phone sorting">指令值</th>
                      <th class="hidden-phone sorting">发送类型</th>
                      <th class="hidden-phone sorting">发送状态</th>
                      <th class="hidden-phone sorting">状态描述</th>
                      <th class="hidden-phone sorting">日期</th>
                    </tr>
                  </thead>
                  <tr class="gradeA odd" v-if="loglist==''">
                    <td colspan="9"><div class="noinfo"><p>最近一个月内,没有控制信息!</p></div></td>
                  </tr>
                  <tbody role="alert" aria-live="polite" aria-relevant="all">
                    <template v-for="log in loglist">
                      <tr class="gradeA odd">
                        <td>{{log.schoolName}}</td>
                        <td v-if="log.collectNumber===0"></td>
                        <td v-else>{{log.collectNumber}}</td>
                        <td v-if="log.fanNumber===0"></td>
                        <td v-else>{{log.fanNumber}}</td>

                        <template v-if="log.controlType===-2">
                          <td>查询采集器状态</td>
                          <td></td>
                        </template>
                        <template v-else-if="log.controlType===-1">
                          <td>查询学校状态</td>
                          <td></td>
                        </template>
                        <template v-else-if="log.controlType===0">
                          <td>查询盘管状态</td>
                          <td></td>
                        </template>

                        <template v-else-if="log.controlType===1">
                          <td>开/关机</td>
                          <td v-if="log.information==1">开机</td>
                          <td v-else-if="log.information==0">关机</td>
                          <td v-else>{{log.information}}</td>
                        </template>


                        <template v-else-if="log.controlType===2">
                          <td>模式</td>
                            <td v-if="log.information==1">制冷</td>
                            <td v-else-if="log.information==2">制热</td>
                            <td v-else-if="log.information==3">除湿</td>
                            <td v-else>{{log.information}}</td>
                        </template>


                        <template v-else-if="log.controlType===3">
                          <td>风速</td>
                            <td v-if="log.information==1">高速</td>
                            <td v-else-if="log.information==2">中速</td>
                            <td v-else-if="log.information==3">低速</td>
                            <td v-else-if="log.information==4">自动</td>
                            <td v-else>{{log.information}}</td>
                        </template>

                        <template v-else-if="log.controlType===4">
                          <td>温度</td>
                          <td>{{log.information}}ºC</td>
                        </template>

                        <template v-else-if="log.controlType===5">
                          <td>循环</td>
                            <td v-if="log.information==1">内循环</td>
                            <td v-else-if="log.information==2">全新风</td>
                            <td v-else-if="log.information==3">自动</td>
                            <td v-else>{{log.information}}</td>
                        </template>

                        <template v-else>
                          <td>其他</td>
                          <td>{{log.information}}</td>
                        </template>


                        <td v-if="log.sendType===0">单台</td>
                        <td v-else>全部</td>
                        <td class="success" v-if="log.sendState===1">成功</td>
                        <td class="danger" v-else>失败</td>
                        <td>{{log.stateInformation}}</td>
                        <td>{{log.tempcreateTime}}</td>
                      </tr>
                    </template>
                  </tbody>
                </table>
                <div class="row-fluid">
                  <div class="span6">
                    <div class="dataTables_paginate paging_bootstrap pagination mypagination">
                      <ul>
                        <li class="prev disabled"><button class="btn btn-default" v-bind:disabled="currentPage<=1" @click="previousPage">上一页</button></li>
                        <li class="next"><button class="btn btn-default" v-bind:disabled="currentPage==totalPage" @click="nextPage">下一页</button></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>
    </section>
  </section>
</template>

<script>
  import myhead from './myhead.vue'
  import mymenu from './mymenu.vue'
  export default {
    name: 'controlLog',
    data () {
      return {
        loglist:[],
        isReflash:false,
        totalPage:0,
        currentPage:0,
        sendState:0,
      }
    },
    mounted () {
      this.controlLogInformation({
        currentPage:this.currentPage+1,
        pageSize:20
      })
      this.setMenu()
    },
    components: {
      myhead,mymenu
    },
    methods:{
      setMenu(){
        this.$refs.mymenu.setMenu('controlLog')
      },
      findState(){
        this.controlLogInformation({
          sendState:this.sendState,
          currentPage:1,
          pageSize:20
        })
      },
      previousPage(){
        this.controlLogInformation({
          sendState:this.sendState,
          currentPage:this.currentPage-1,
          pageSize:20
        })
      },
      nextPage(){
        this.controlLogInformation({
          sendState:this.sendState,
          currentPage:this.currentPage+1,
          pageSize:20
        })
      },
      controlLogInformation:function(param){
        var that = this
        var token = sessionStorage.getItem('shiro-token')
        if (!token) {
          that.$router.push({path: '/'})
          return true
        }else{
          var instance = this.$axios.create({
            headers: {'Authorization':token}
          });
          instance.post('ganzi-server/info/controlInformation',param)
          .then(function (response) {
            if(response.data.code == '200'){
              if(response.data.data && response.data.data.length>0 ){
                that.loglist = response.data.data
              }
              that.totalPage = response.data.totalPage
              that.currentPage = response.data.currentPage
            }else{
              that.showToast(response.data.msg)
            }
          })
          .catch(function (error) {
            if(error.response && error.response.data.status == 4001){
              sessionStorage.clear();
              that.$router.push({path: '/'})
            }else if(error.response && error.response.data.status == 4002){
              sessionStorage.clear();
              that.$options.methods.showToast('您的账号在其他地方登录,如非本人操作，请立即修改密码！')
              that.$router.push({path: '/'})
            }else{
              that.$options.methods.showToast('系统异常!')
            }
          });
        }
      },
      showToast:function(msg){
        $.alert({
          title: '消息!',
          content: msg,
          confirmButton: '确定',
          confirmButtonClass: 'btn-warning',
          backgroundDismiss: false,
          confirm: function(){
          }
        });
      }
    }
  }
</script>

<style scoped>
  @import "../assets/css/to-do.css";
  @import "../assets/css/school.css";
</style>
